<template>

  <view v-if="pageAlready" class="pageBg pd2628 box-b">

    <!-- 轮播图 -->
    <view
      v-if="advertisements && advertisements.length > 0"
    >
      <!--   advertisements列表只有一个不显示swiper   -->
      <view
        v-if="advertisements && advertisements.length == 1 && advertisements[0]"
        class="relative w694 h918 radius20 ovfh"
        @click="goSwiperProduct(advertisements[0])">
        <c-image
          v-if="advertisements[0].url"
          className="w694 h918 disb"
          borderRadius="12rpx"
          :src="advertisements[0].url"
          mode="scaleToFill">
        </c-image>
      </view>
      <swiper
        v-if="advertisements && advertisements.length > 1"
        class="swiper relative w694 h918 radius20 ovfh"
        :autoplay="true"
        :interval="3000"
        :duration="1000"
        :indicator-dots="true"
        indicator-active-color="#0095FF"
        indicator-color="#7F8797"
        @change="swiperChange"
      >
        <block v-for="(item, index) in advertisements" :key="index">
          <swiper-item>
            <view
              class="swiper-item radius20 w694 h918 flex-box tac ovfh"
              @click="goSwiperProduct(item)"
            >
              <c-image
                v-if="item.url"
                className="w694 h918 disb"
                borderRadius="12rpx"
                :src="item.url"
                mode="scaleToFill">
              </c-image>
            </view>
          </swiper-item>
        </block>
      </swiper>
    </view>

    <view class="between-box mgt24">
      <view class="flex1 bgff radius12 pd50203820 box-b tac mgr10"
            @click="toPage('/pages/product/repair-report/repair-report-detail',true)">
        <view class="wh110 flex-box mga">
          <server-image
            class="img110 mga disb"
            name="repair/20241028001.png"
            mode="aspectFill" />
        </view>
        <view class="mgt30 fs28 color26 ffmi fw500">
          我要报修
        </view>
      </view>
      <view class="flex1 bgff radius12 pd50203820 box-b tac mgl10"
            @click="toAfterservice">
        <view class="wh110 flex-box mga">
          <server-image
            class="img110 mga disb"
            name="repair/20241028002.png"
            mode="aspectFill" />
        </view>
        <view class="mgt30 fs28 color26 ffmi fw500">
          报修记录
        </view>
      </view>
    </view>

  </view>

  <view v-else class="flex-box" style="height: 750rpx">
    <u-loading></u-loading>
  </view>

</template>

<script>
import { mapState } from 'vuex';
import config, { mergeConfig } from "@/common/config";
// const alreadyAgree = uni.getStorageSync('alreadyAgreePrivacyAgreement');
export default {
  data() {
    return {
      showOrder: false,
      advertisements: [],
      swiperCurrent: 0,
      // pageAlready: false,
      pageAlready: true,
    };
  },
  computed: {
    ...mapState({
      memberInfo: (state) => state.memberInfo || {},
      // systemInfo: (state) => state.systemInfo || {},
      // systemNow: (state) => state.systemNow,
    }),
  },
  onLoad() {
    const vm = this;
    // #ifdef APP-PLUS
    // if (alreadyAgree !== 1) return;
    // this.appInit();
    // #endif
    vm.onloadH5();
  },
  onShow() {
    const formEnter = uni.getStorageSync('formEnter');
    if (formEnter) {
      uni.removeStorageSync('formEnter');
    }
    const pagefromDetail = uni.getStorageSync('pagefromDetail');
    if (pagefromDetail) {
      uni.removeStorageSync('pagefromDetail');
    }
    const memberAutoId = uni.getStorageSync('memberAutoId');
    if (memberAutoId) {
      uni.removeStorageSync('memberAutoId');
    }
  },
  onPullDownRefresh() {
    this.onloadH5().then(()=>{
      uni.stopPullDownRefresh();
    })
  },
  onReady() {
    // #ifdef APP-PLUS
    this.subNVUEShow();
    // #endif
  },
  methods: {
    // app start
    // appInit() {
    //   const BaseModule = uni.requireNativePlugin('UniPlugin-BaseModule');
    //   if (BaseModule) BaseModule.initApp();
    // },
    // async subNVUEShow() {
    //   if (alreadyAgree !== 1) {
    //     uni.$on('page-privacy-agreement-modal-agree', async () => {
    //       mergeConfig();
    //       await this.$store.dispatch('getSystemInfo');
    //       if (this.systemInfo.allShutdown == 'true')
    //         uni.$emit('page-shutdown-modal', 'show', config);
    //       this.appInit();
    //       this.onloadH5();
    //       uni.$emit('page-update-modal', this.systemInfo, config);
    //     });
    //     uni.$emit('page-privacy-agreement-modal', 'show', config);
    //     return;
    //   }
    //   await this.$store.dispatch('getSystemInfo');
    //   if (this.systemInfo.allShutdown == 'true') uni.$emit('page-shutdown-modal', 'show', config);
    //   uni.$emit('page-update-modal', this.systemInfo, config);
    // },
    // app end
    initListDate(){
      const vm = this;
      vm.showOrder = false
      vm.advertisements = []
      vm.swiperCurrent = 0
    },
    onloadH5() {
      const vm = this;
      vm.initListDate()
      return  new Promise((resove)=>{

        vm.api_ui_getindexbannerlist().finally(()=>{
          resove()
        })

      })
    },
    api_ui_getindexbannerlist() {
      const vm = this;

      // eslint-disable-next-line no-unreachable
      this.pageAlready = true;
      uni.showLoading({
        title: '加载中...'
      })
      return  new Promise((resove)=>{
        vm.apiUrl
          .api_ui_getindexbannerlist()
          .then((res) => {
            uni.hideLoading();
            // console.log("advertisements", res.data)
            const { code, data: {
              list = []
            } } = res.data
            if (code == 0) {
              if (list && list.length > 0) {
                if (list) {
                  vm.advertisements = list || [];
                }
              }
            }
            resove()
          })

      })
    },
    swiperChange(o) {
      this.swiperCurrent = o.detail.current
    },

    goSwiperProduct(item) {
      // const vm = this
      // if(item.type_id == 1) {
      //   uni.navigateTo({
      //     url: '/pages/index/webPage/webPage?type=' + item.type + '&title=' + item.title
      //   });
      // } else if (item.type_id == 2) {
      //   uni.navigateTo({
      //     url: '/pages/index/webPage/webPage?url=' + item.links + '&title=' + item.title
      //   });
      // } else if (item.type_id == 3) {
      //   console.log("纯展示")
      // }
    },
    async  bindProduct(){
      const vm = this
      // await vm.$store.dispatch('check_wx_login')
      vm.showMessage({
        title: '暂未开放，敬请期待。',
        duration: 1500
      })
    },
    async  toAfterservice(){
      const vm = this
      if(!vm.memberInfo.openid){
        await vm.$store.dispatch('check_wx_login')
      }
      vm.toPage('/pages/product/repair-report/repair-report',true)
    },

  },
};
</script>

<style lang="less" scoped>

</style>
